<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%article_category}}".
 *
 * @property int $id ID标识
 * @property int $tree 多树标识，如前后台等
 * @property int $lft 左节点
 * @property int $rgt 右节点
 * @property int $depth 深度
 * @property string $name 分类名
 * @property string $alias 别名
 * @property int $sort 排序
 * @property string $remark 备注
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 *
 * @property Article[] $articles
 */
class ArticleCategory extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%article_category}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['tree', 'lft', 'rgt', 'depth', 'sort', 'created_at', 'updated_at'], 'integer'],
            [['lft', 'rgt', 'depth', 'name'], 'required'],
            [['name', 'alias', 'remark'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id'         => 'ID标识',
            'tree'       => '多树标识，如前后台等',
            'lft'        => '左节点',
            'rgt'        => '右节点',
            'depth'      => '深度',
            'name'       => '分类名',
            'alias'      => '别名',
            'sort'       => '排序',
            'remark'     => '备注',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getArticles()
    {
        return $this->hasMany(Article::className(), ['article_category_id' => 'id']);
    }

    /**
     * {@inheritdoc}
     * @return ArticleCategoryQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new ArticleCategoryQuery(get_called_class());
    }
}
